package com.example.finger.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.finger.R;
import com.lyxmaster.lib.util.DataConfig;

import java.util.List;

/**
 * Created by LU-MAC on 2018/11/25.
 */

public class TaskInfoAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;
    private int height;

    public TaskInfoAdapter(Context context,List<String> list){
        this.context = context;
        this.list = list;
        height = DataConfig.dp2px(context, 40);
    }

    public TaskInfoAdapter(Context context,List<String> list, int height){
        this.context = context;
        this.list = list;
        this.height = DataConfig.dp2px(context, height);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adpter_task_info, null);

            viewHolder = new ViewHolder();
            viewHolder.textViewName = convertView.findViewById(R.id.tv_name);
            viewHolder.textViewNum = convertView.findViewById(R.id.tv_num);
            viewHolder.relativeLayout = convertView.findViewById(R.id.layout);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.textViewNum.setText(position+1 + "");
        viewHolder.textViewName.setText(list.get(position));
        ViewGroup.LayoutParams params=viewHolder.relativeLayout.getLayoutParams();
        params.height =this.height;
        viewHolder.relativeLayout.setLayoutParams(params);

        return convertView;
    }

    class ViewHolder {
        public TextView textViewName;
        public TextView textViewNum;
        public RelativeLayout relativeLayout;
    }
}
